<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>项目启动 | SPEED 团队企业级中台组件</title>
    <meta name="generator" content="VuePress 1.9.7">
    <link rel="icon" href="$withBase(&#39;/avatar.png&#39;)">
    <meta name="description" content="">
    
    <link rel="preload" href="/assets/css/0.styles.4a390c75.css" as="style"><link rel="preload" href="/assets/js/app.9e59f384.js" as="script"><link rel="preload" href="/assets/js/2.61252cf6.js" as="script"><link rel="preload" href="/assets/js/14.5f5c406e.js" as="script"><link rel="prefetch" href="/assets/js/10.47abf4f2.js"><link rel="prefetch" href="/assets/js/11.f25fa446.js"><link rel="prefetch" href="/assets/js/12.b817a6b9.js"><link rel="prefetch" href="/assets/js/13.a9ff20a6.js"><link rel="prefetch" href="/assets/js/3.a4b7a9d2.js"><link rel="prefetch" href="/assets/js/4.8bbc0415.js"><link rel="prefetch" href="/assets/js/5.64a3d90d.js"><link rel="prefetch" href="/assets/js/6.65875694.js"><link rel="prefetch" href="/assets/js/7.c347ceab.js"><link rel="prefetch" href="/assets/js/8.07cb2ef7.js"><link rel="prefetch" href="/assets/js/9.be610aef.js">
    <link rel="stylesheet" href="/assets/css/0.styles.4a390c75.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/avatar.png" alt="SPEED 团队企业级中台组件" class="logo"> <span class="site-name can-hide">SPEED 团队企业级中台组件</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="业务中台" class="dropdown-title"><span class="title">业务中台</span> <span class="arrow down"></span></button> <button type="button" aria-label="业务中台" class="mobile-dropdown-title"><span class="title">业务中台</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/业务中台组件/登录认证授权组件.html" class="nav-link">
  登录认证授权组件
</a></li><li class="dropdown-item"><!----> <a href="/业务中台组件/数据脱敏组件.html" class="nav-link">
  数据脱敏组件
</a></li><li class="dropdown-item"><!----> <a href="/业务中台组件/OBS 对象存储组件.html" class="nav-link">
  OBS 对象存储组件
</a></li><li class="dropdown-item"><!----> <a href="/业务中台组件/邮件发送组件.html" class="nav-link">
  邮件发送组件
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="数据中台" class="dropdown-title"><span class="title">数据中台</span> <span class="arrow down"></span></button> <button type="button" aria-label="数据中台" class="mobile-dropdown-title"><span class="title">数据中台</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/数据中台组件/钉钉告警组件.html" class="nav-link">
  钉钉告警组件
</a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="业务中台" class="dropdown-title"><span class="title">业务中台</span> <span class="arrow down"></span></button> <button type="button" aria-label="业务中台" class="mobile-dropdown-title"><span class="title">业务中台</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/业务中台组件/登录认证授权组件.html" class="nav-link">
  登录认证授权组件
</a></li><li class="dropdown-item"><!----> <a href="/业务中台组件/数据脱敏组件.html" class="nav-link">
  数据脱敏组件
</a></li><li class="dropdown-item"><!----> <a href="/业务中台组件/OBS 对象存储组件.html" class="nav-link">
  OBS 对象存储组件
</a></li><li class="dropdown-item"><!----> <a href="/业务中台组件/邮件发送组件.html" class="nav-link">
  邮件发送组件
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="数据中台" class="dropdown-title"><span class="title">数据中台</span> <span class="arrow down"></span></button> <button type="button" aria-label="数据中台" class="mobile-dropdown-title"><span class="title">数据中台</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/数据中台组件/钉钉告警组件.html" class="nav-link">
  钉钉告警组件
</a></li></ul></div></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>业务中台</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/业务中台组件/登录认证授权组件.html" class="sidebar-link">登录认证授权组件</a></li><li><a href="/业务中台组件/数据脱敏组件.html" class="sidebar-link">数据脱敏组件</a></li><li><a href="/业务中台组件/OBS 对象存储组件.html" class="sidebar-link">OBS 对象存储组件</a></li><li><a href="/业务中台组件/邮件发送组件.html" class="sidebar-link">邮件发送组件</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>数据中台</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/数据中台组件/钉钉告警组件.html" class="sidebar-link">钉钉告警组件</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="项目启动"><a href="#项目启动" class="header-anchor">#</a> 项目启动</h1> <h2 id="启动-nacos"><a href="#启动-nacos" class="header-anchor">#</a> 启动 nacos</h2> <blockquote><p>单例运行，修改 nacos 配置, 如 D:\java\nacos\nacos\bin\shutdown.cmd</p> <p>set MODE=&quot;standalone&quot;</p></blockquote> <h2 id="启动-redis"><a href="#启动-redis" class="header-anchor">#</a> 启动 redis</h2> <h2 id="启动认证鉴权中心"><a href="#启动认证鉴权中心" class="header-anchor">#</a> 启动认证鉴权中心</h2> <p>SPEEDOauth2ServerApplication</p> <h2 id="启动网关服务"><a href="#启动网关服务" class="header-anchor">#</a> 启动网关服务</h2> <p>SPEEDOauth2GatewayApplication</p> <h2 id="启动子项目"><a href="#启动子项目" class="header-anchor">#</a> 启动子项目</h2> <h1 id="公共层"><a href="#公共层" class="header-anchor">#</a> 公共层</h1> <h2 id="公共接口"><a href="#公共接口" class="header-anchor">#</a> 公共接口</h2> <div class="language-ruby extra-class"><pre class="language-ruby"><code>package com<span class="token punctuation">.</span><span class="token constant">SPEED</span><span class="token punctuation">.</span>common<span class="token punctuation">.</span>controller<span class="token punctuation">;</span>

import com<span class="token punctuation">.</span>baomidou<span class="token punctuation">.</span>mybatisplus<span class="token punctuation">.</span>extension<span class="token punctuation">.</span>service<span class="token punctuation">.</span>IService<span class="token punctuation">;</span>
import com<span class="token punctuation">.</span><span class="token constant">SPEED</span><span class="token punctuation">.</span>common<span class="token punctuation">.</span>model<span class="token punctuation">.</span><span class="token constant">R</span><span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>beans<span class="token punctuation">.</span>factory<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span>Autowired<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>web<span class="token punctuation">.</span>bind<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span>DeleteMapping<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>web<span class="token punctuation">.</span>bind<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span>PathVariable<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>web<span class="token punctuation">.</span>bind<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span>PostMapping<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>web<span class="token punctuation">.</span>bind<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span>RequestBody<span class="token punctuation">;</span>
import reactor<span class="token punctuation">.</span>core<span class="token punctuation">.</span>publisher<span class="token punctuation">.</span>Mono<span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">BaseAdapter</span><span class="token operator">&lt;</span><span class="token constant">T</span><span class="token operator">&gt;</span> <span class="token punctuation">{</span>

    <span class="token variable">@Autowired</span>
    <span class="token keyword">private</span> IService<span class="token operator">&lt;</span><span class="token constant">T</span><span class="token operator">&gt;</span> baseService<span class="token punctuation">;</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 新增订单数据
     <span class="token operator">*</span> <span class="token variable">@param</span> t
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token variable">@PostMapping</span><span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;/insert&quot;</span></span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> Mono<span class="token operator">&lt;</span><span class="token constant">R</span><span class="token operator">&gt;</span> insert<span class="token punctuation">(</span><span class="token variable">@RequestBody</span> <span class="token constant">T</span> t<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>baseService<span class="token punctuation">.</span>save<span class="token punctuation">(</span>t<span class="token punctuation">)</span><span class="token punctuation">)</span>
            <span class="token keyword">return</span> Mono<span class="token punctuation">.</span>just<span class="token punctuation">(</span><span class="token constant">R</span><span class="token punctuation">.</span>ok<span class="token punctuation">(</span>t<span class="token punctuation">,</span> <span class="token string-literal"><span class="token string">&quot;新增成功&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> Mono<span class="token punctuation">.</span>just<span class="token punctuation">(</span><span class="token constant">R</span><span class="token punctuation">.</span>fail<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 更新
     <span class="token operator">*</span> <span class="token variable">@param</span> t
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token variable">@PostMapping</span><span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;/update&quot;</span></span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> Mono<span class="token operator">&lt;</span><span class="token constant">R</span><span class="token operator">&gt;</span> update<span class="token punctuation">(</span><span class="token variable">@RequestBody</span> <span class="token constant">T</span> t<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>baseService<span class="token punctuation">.</span>updateById<span class="token punctuation">(</span>t<span class="token punctuation">)</span><span class="token punctuation">)</span>
            <span class="token keyword">return</span> Mono<span class="token punctuation">.</span>just<span class="token punctuation">(</span><span class="token constant">R</span><span class="token punctuation">.</span>ok<span class="token punctuation">(</span>t<span class="token punctuation">,</span> <span class="token string-literal"><span class="token string">&quot;更新成功&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> Mono<span class="token punctuation">.</span>just<span class="token punctuation">(</span><span class="token constant">R</span><span class="token punctuation">.</span>fail<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 删除
     <span class="token operator">*</span> <span class="token variable">@param</span> id
     <span class="token operator">*</span> <span class="token variable">@return</span>
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token variable">@DeleteMapping</span><span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;/delete/{id}&quot;</span></span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> Mono<span class="token operator">&lt;</span><span class="token constant">R</span><span class="token operator">&gt;</span> delete<span class="token punctuation">(</span><span class="token variable">@PathVariable</span><span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;id&quot;</span></span><span class="token punctuation">)</span> <span class="token builtin">String</span> id<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>baseService<span class="token punctuation">.</span>removeById<span class="token punctuation">(</span>id<span class="token punctuation">)</span><span class="token punctuation">)</span>
            <span class="token keyword">return</span> Mono<span class="token punctuation">.</span>just<span class="token punctuation">(</span><span class="token constant">R</span><span class="token punctuation">.</span>ok<span class="token punctuation">(</span>null<span class="token punctuation">,</span> <span class="token string-literal"><span class="token string">&quot;删除成功&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> Mono<span class="token punctuation">.</span>just<span class="token punctuation">(</span><span class="token constant">R</span><span class="token punctuation">.</span>fail<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

<span class="token punctuation">}</span>

</code></pre></div><h2 id="使用示例"><a href="#使用示例" class="header-anchor">#</a> 使用示例</h2> <div class="language-ruby extra-class"><pre class="language-ruby"><code>package com<span class="token punctuation">.</span><span class="token constant">SPEED</span><span class="token punctuation">.</span>bussiness<span class="token punctuation">.</span>order<span class="token punctuation">.</span>controller<span class="token punctuation">;</span>

import com<span class="token punctuation">.</span>baomidou<span class="token punctuation">.</span>dynamic<span class="token punctuation">.</span>datasource<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span><span class="token constant">DS</span><span class="token punctuation">;</span>
import com<span class="token punctuation">.</span>baomidou<span class="token punctuation">.</span>mybatisplus<span class="token punctuation">.</span>core<span class="token punctuation">.</span>metadata<span class="token punctuation">.</span>IPage<span class="token punctuation">;</span>
import com<span class="token punctuation">.</span><span class="token constant">SPEED</span><span class="token punctuation">.</span>bussiness<span class="token punctuation">.</span>order<span class="token punctuation">.</span>model<span class="token punctuation">.</span>OrderInfo<span class="token punctuation">;</span>
import com<span class="token punctuation">.</span><span class="token constant">SPEED</span><span class="token punctuation">.</span>bussiness<span class="token punctuation">.</span>order<span class="token punctuation">.</span>model<span class="token punctuation">.</span>vo<span class="token punctuation">.</span>OrderInfoVO<span class="token punctuation">;</span>
import com<span class="token punctuation">.</span><span class="token constant">SPEED</span><span class="token punctuation">.</span>bussiness<span class="token punctuation">.</span>order<span class="token punctuation">.</span>service<span class="token punctuation">.</span>OrderInfoService<span class="token punctuation">;</span>
import com<span class="token punctuation">.</span><span class="token constant">SPEED</span><span class="token punctuation">.</span>common<span class="token punctuation">.</span>model<span class="token punctuation">.</span><span class="token constant">R</span><span class="token punctuation">;</span>
import com<span class="token punctuation">.</span><span class="token constant">SPEED</span><span class="token punctuation">.</span>common<span class="token punctuation">.</span>controller<span class="token punctuation">.</span>BaseAdapter<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>beans<span class="token punctuation">.</span>factory<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span>Autowired<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>web<span class="token punctuation">.</span>bind<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span><span class="token operator">*</span><span class="token punctuation">;</span>
import reactor<span class="token punctuation">.</span>core<span class="token punctuation">.</span>publisher<span class="token punctuation">.</span>Mono<span class="token punctuation">;</span>

<span class="token variable">@RestController</span>
<span class="token variable">@RequestMapping</span><span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;/bussiness-order&quot;</span></span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">OrderInfoController</span> extends BaseAdapter<span class="token operator">&lt;</span>OrderInfo<span class="token operator">&gt;</span> <span class="token punctuation">{</span>

    <span class="token variable">@Autowired</span>
    <span class="token keyword">private</span> OrderInfoService orderInfoService<span class="token punctuation">;</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 获取订单数据列表
     <span class="token operator">*</span> <span class="token variable">@return</span>
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token variable">@DS</span><span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;slave&quot;</span></span><span class="token punctuation">)</span>
    <span class="token variable">@GetMapping</span><span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;/selectList&quot;</span></span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> Mono<span class="token operator">&lt;</span>IPage<span class="token operator">&lt;</span>OrderInfo<span class="token operator">&gt;&gt;</span> selectList<span class="token punctuation">(</span>OrderInfoVO vo<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> Mono<span class="token punctuation">.</span>just<span class="token punctuation">(</span>orderInfoService<span class="token punctuation">.</span>selectList<span class="token punctuation">(</span>vo<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token variable">@GetMapping</span><span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;/hello&quot;</span></span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> Mono<span class="token operator">&lt;</span><span class="token builtin">String</span><span class="token operator">&gt;</span> hello<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> Mono<span class="token punctuation">.</span>just<span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;hello&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>


    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 新增订单数据
     <span class="token operator">*</span> <span class="token variable">@param</span> orderInfo
     <span class="token operator">*</span> <span class="token variable">@return</span>
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token variable">@DS</span><span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;slave&quot;</span></span><span class="token punctuation">)</span>
    <span class="token variable">@Override</span>
    <span class="token keyword">public</span> Mono<span class="token operator">&lt;</span><span class="token constant">R</span><span class="token operator">&gt;</span> insert<span class="token punctuation">(</span><span class="token variable">@RequestBody</span> OrderInfo orderInfo<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token keyword">super</span><span class="token punctuation">.</span>insert<span class="token punctuation">(</span>orderInfo<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 更新订单数据
     <span class="token operator">*</span> <span class="token variable">@param</span> orderInfo
     <span class="token operator">*</span> <span class="token variable">@return</span>
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token variable">@DS</span><span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;slave&quot;</span></span><span class="token punctuation">)</span>
    <span class="token variable">@Override</span>
    <span class="token keyword">public</span> Mono<span class="token operator">&lt;</span><span class="token constant">R</span><span class="token operator">&gt;</span> update<span class="token punctuation">(</span><span class="token variable">@RequestBody</span> OrderInfo orderInfo<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token keyword">super</span><span class="token punctuation">.</span>update<span class="token punctuation">(</span>orderInfo<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 删除订单数据
     <span class="token operator">*</span> <span class="token variable">@param</span> id
     <span class="token operator">*</span> <span class="token variable">@return</span>
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token variable">@DS</span><span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;slave&quot;</span></span><span class="token punctuation">)</span>
    <span class="token variable">@Override</span>
    <span class="token keyword">public</span> Mono<span class="token operator">&lt;</span><span class="token constant">R</span><span class="token operator">&gt;</span> delete<span class="token punctuation">(</span><span class="token variable">@PathVariable</span> <span class="token builtin">String</span> id<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token keyword">super</span><span class="token punctuation">.</span>delete<span class="token punctuation">(</span>id<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

<span class="token punctuation">}</span>

</code></pre></div><h1 id="持久层"><a href="#持久层" class="header-anchor">#</a> 持久层</h1> <h2 id="mybatis-plus"><a href="#mybatis-plus" class="header-anchor">#</a> Mybatis plus</h2> <div class="language-ruby extra-class"><pre class="language-ruby"><code>        <span class="token operator">&lt;</span>dependency<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>groupId<span class="token operator">&gt;</span>com<span class="token punctuation">.</span>baomidou<span class="token operator">&lt;</span><span class="token operator">/</span>groupId<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>artifactId<span class="token operator">&gt;</span>mybatis<span class="token operator">-</span>plus<span class="token operator">-</span>boot<span class="token operator">-</span>starter<span class="token operator">&lt;</span><span class="token operator">/</span>artifactId<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>version<span class="token operator">&gt;</span><span class="token number">3.5</span><span class="token number">.1</span><span class="token operator">&lt;</span><span class="token operator">/</span>version<span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span><span class="token operator">/</span>dependency<span class="token operator">&gt;</span>
</code></pre></div><h2 id="分页插件"><a href="#分页插件" class="header-anchor">#</a> 分页插件</h2> <div class="language-ruby extra-class"><pre class="language-ruby"><code>        <span class="token operator">&lt;</span>dependency<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>groupId<span class="token operator">&gt;</span>com<span class="token punctuation">.</span>github<span class="token punctuation">.</span>pagehelper<span class="token operator">&lt;</span><span class="token operator">/</span>groupId<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>artifactId<span class="token operator">&gt;</span>pagehelper<span class="token operator">-</span>spring<span class="token operator">-</span>boot<span class="token operator">-</span>starter<span class="token operator">&lt;</span><span class="token operator">/</span>artifactId<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>version<span class="token operator">&gt;</span><span class="token number">1.4</span><span class="token number">.1</span><span class="token operator">&lt;</span><span class="token operator">/</span>version<span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span><span class="token operator">/</span>dependency<span class="token operator">&gt;</span>

</code></pre></div><h2 id="动态多数据源"><a href="#动态多数据源" class="header-anchor">#</a> 动态多数据源</h2> <h3 id="依赖"><a href="#依赖" class="header-anchor">#</a> 依赖</h3> <div class="language-ruby extra-class"><pre class="language-ruby"><code>        <span class="token operator">&lt;</span>dependency<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>groupId<span class="token operator">&gt;</span>com<span class="token punctuation">.</span>baomidou<span class="token operator">&lt;</span><span class="token operator">/</span>groupId<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>artifactId<span class="token operator">&gt;</span>dynamic<span class="token operator">-</span>datasource<span class="token operator">-</span>spring<span class="token operator">-</span>boot<span class="token operator">-</span>starter<span class="token operator">&lt;</span><span class="token operator">/</span>artifactId<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>version<span class="token operator">&gt;</span><span class="token number">2.5</span><span class="token number">.6</span><span class="token operator">&lt;</span><span class="token operator">/</span>version<span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span><span class="token operator">/</span>dependency<span class="token operator">&gt;</span>
</code></pre></div><h3 id="使用示例-2"><a href="#使用示例-2" class="header-anchor">#</a> 使用示例</h3> <div class="language-ruby extra-class"><pre class="language-ruby"><code>    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 更新订单数据
     <span class="token operator">*</span> <span class="token variable">@param</span> orderInfo
     <span class="token operator">*</span> <span class="token variable">@return</span>
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token variable">@DS</span><span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;slave&quot;</span></span><span class="token punctuation">)</span>
    <span class="token variable">@Override</span>
    <span class="token keyword">public</span> Mono<span class="token operator">&lt;</span><span class="token constant">R</span><span class="token operator">&gt;</span> update<span class="token punctuation">(</span><span class="token variable">@RequestBody</span> OrderInfo orderInfo<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token keyword">super</span><span class="token punctuation">.</span>update<span class="token punctuation">(</span>orderInfo<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

</code></pre></div><h1 id="全局唯一-id"><a href="#全局唯一-id" class="header-anchor">#</a> 全局唯一 id</h1> <p>百度 uid</p> <div class="language-ruby extra-class"><pre class="language-ruby"><code>    <span class="token variable">@Autowired</span>
    <span class="token keyword">private</span> UidGenerator uidGenerator<span class="token punctuation">;</span>
</code></pre></div><h1 id="新建子模块"><a href="#新建子模块" class="header-anchor">#</a> 新建子模块</h1> <h2 id="依赖-2"><a href="#依赖-2" class="header-anchor">#</a> 依赖</h2> <div class="language-ruby extra-class"><pre class="language-ruby"><code><span class="token operator">&lt;</span><span class="token operator">?</span>xml version<span class="token operator">=</span><span class="token string-literal"><span class="token string">&quot;1.0&quot;</span></span> encoding<span class="token operator">=</span><span class="token string-literal"><span class="token string">&quot;UTF-8&quot;</span></span><span class="token operator">?</span><span class="token operator">&gt;</span>
<span class="token operator">&lt;</span>project xmlns<span class="token operator">=</span><span class="token string-literal"><span class="token string">&quot;http://maven.apache.org/POM/4.0.0&quot;</span></span>
         <span class="token symbol">xmlns</span><span class="token symbol">:xsi</span><span class="token operator">=</span><span class="token string-literal"><span class="token string">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
         <span class="token symbol">xsi</span><span class="token symbol">:schemaLocation</span><span class="token operator">=</span><span class="token string-literal"><span class="token string">&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;</span></span><span class="token operator">&gt;</span>

    <span class="token operator">&lt;</span>parent<span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span>artifactId<span class="token operator">&gt;</span><span class="token constant">SPEED</span><span class="token operator">-</span>bussiness<span class="token operator">&lt;</span><span class="token operator">/</span>artifactId<span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span>groupId<span class="token operator">&gt;</span>com<span class="token punctuation">.</span><span class="token constant">SPEED</span><span class="token operator">&lt;</span><span class="token operator">/</span>groupId<span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span>version<span class="token operator">&gt;</span><span class="token number">0.0</span><span class="token number">.1</span><span class="token operator">-</span><span class="token constant">SNAPSHOT</span><span class="token operator">&lt;</span><span class="token operator">/</span>version<span class="token operator">&gt;</span>
    <span class="token operator">&lt;</span><span class="token operator">/</span>parent<span class="token operator">&gt;</span>

    <span class="token operator">&lt;</span>modelVersion<span class="token operator">&gt;</span><span class="token number">4.0</span><span class="token number">.0</span><span class="token operator">&lt;</span><span class="token operator">/</span>modelVersion<span class="token operator">&gt;</span>

    <span class="token operator">&lt;</span>artifactId<span class="token operator">&gt;</span><span class="token constant">SPEED</span><span class="token operator">-</span>bussiness<span class="token operator">-</span>order<span class="token operator">&lt;</span><span class="token operator">/</span>artifactId<span class="token operator">&gt;</span>

    <span class="token operator">&lt;</span>dependencies<span class="token operator">&gt;</span>

        <span class="token operator">&lt;</span>dependency<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>groupId<span class="token operator">&gt;</span>com<span class="token punctuation">.</span><span class="token constant">SPEED</span><span class="token operator">&lt;</span><span class="token operator">/</span>groupId<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>artifactId<span class="token operator">&gt;</span><span class="token constant">SPEED</span><span class="token operator">-</span>uid<span class="token operator">&lt;</span><span class="token operator">/</span>artifactId<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>version<span class="token operator">&gt;</span><span class="token number">0.0</span><span class="token number">.1</span><span class="token operator">-</span><span class="token constant">SNAPSHOT</span><span class="token operator">&lt;</span><span class="token operator">/</span>version<span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span><span class="token operator">/</span>dependency<span class="token operator">&gt;</span>

        <span class="token operator">&lt;</span><span class="token operator">!</span><span class="token operator">-</span><span class="token operator">-</span>nacos注册中心<span class="token operator">-</span><span class="token operator">-</span><span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span>dependency<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>groupId<span class="token operator">&gt;</span>com<span class="token punctuation">.</span>alibaba<span class="token punctuation">.</span>cloud<span class="token operator">&lt;</span><span class="token operator">/</span>groupId<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>artifactId<span class="token operator">&gt;</span>spring<span class="token operator">-</span>cloud<span class="token operator">-</span>starter<span class="token operator">-</span>alibaba<span class="token operator">-</span>nacos<span class="token operator">-</span>discovery<span class="token operator">&lt;</span><span class="token operator">/</span>artifactId<span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span><span class="token operator">/</span>dependency<span class="token operator">&gt;</span>

        <span class="token operator">&lt;</span>dependency<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>groupId<span class="token operator">&gt;</span>org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>boot<span class="token operator">&lt;</span><span class="token operator">/</span>groupId<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>artifactId<span class="token operator">&gt;</span>spring<span class="token operator">-</span>boot<span class="token operator">-</span>starter<span class="token operator">-</span>web<span class="token operator">&lt;</span><span class="token operator">/</span>artifactId<span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span><span class="token operator">/</span>dependency<span class="token operator">&gt;</span>

        <span class="token operator">&lt;</span><span class="token operator">!</span><span class="token operator">-</span><span class="token operator">-</span> mysql <span class="token operator">-</span><span class="token operator">-</span><span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span>dependency<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>groupId<span class="token operator">&gt;</span>mysql<span class="token operator">&lt;</span><span class="token operator">/</span>groupId<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>artifactId<span class="token operator">&gt;</span>mysql<span class="token operator">-</span>connector<span class="token operator">-</span>java<span class="token operator">&lt;</span><span class="token operator">/</span>artifactId<span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span><span class="token operator">/</span>dependency<span class="token operator">&gt;</span>

        <span class="token operator">&lt;</span>dependency<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>groupId<span class="token operator">&gt;</span>com<span class="token punctuation">.</span><span class="token constant">SPEED</span><span class="token operator">&lt;</span><span class="token operator">/</span>groupId<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>artifactId<span class="token operator">&gt;</span><span class="token constant">SPEED</span><span class="token operator">-</span>oauth2<span class="token operator">-</span>common<span class="token operator">&lt;</span><span class="token operator">/</span>artifactId<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>version<span class="token operator">&gt;</span><span class="token number">0.0</span><span class="token number">.1</span><span class="token operator">-</span><span class="token constant">SNAPSHOT</span><span class="token operator">&lt;</span><span class="token operator">/</span>version<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>exclusions<span class="token operator">&gt;</span>
                <span class="token operator">&lt;</span>exclusion<span class="token operator">&gt;</span>
                    <span class="token operator">&lt;</span>groupId<span class="token operator">&gt;</span>org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>boot<span class="token operator">&lt;</span><span class="token operator">/</span>groupId<span class="token operator">&gt;</span>
                    <span class="token operator">&lt;</span>artifactId<span class="token operator">&gt;</span>spring<span class="token operator">-</span>boot<span class="token operator">-</span>starter<span class="token operator">-</span>security<span class="token operator">&lt;</span><span class="token operator">/</span>artifactId<span class="token operator">&gt;</span>
                <span class="token operator">&lt;</span><span class="token operator">/</span>exclusion<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span><span class="token operator">/</span>exclusions<span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span><span class="token operator">/</span>dependency<span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span>dependency<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>groupId<span class="token operator">&gt;</span>com<span class="token punctuation">.</span><span class="token constant">SPEED</span><span class="token operator">&lt;</span><span class="token operator">/</span>groupId<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>artifactId<span class="token operator">&gt;</span><span class="token constant">SPEED</span><span class="token operator">-</span>oauth2<span class="token operator">-</span>starter<span class="token operator">&lt;</span><span class="token operator">/</span>artifactId<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>version<span class="token operator">&gt;</span><span class="token number">0.0</span><span class="token number">.1</span><span class="token operator">-</span><span class="token constant">SNAPSHOT</span><span class="token operator">&lt;</span><span class="token operator">/</span>version<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>scope<span class="token operator">&gt;</span>compile<span class="token operator">&lt;</span><span class="token operator">/</span>scope<span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span><span class="token operator">/</span>dependency<span class="token operator">&gt;</span>

    <span class="token operator">&lt;</span><span class="token operator">/</span>dependencies<span class="token operator">&gt;</span>

<span class="token operator">&lt;</span><span class="token operator">/</span>project<span class="token operator">&gt;</span>
</code></pre></div><h2 id="配置"><a href="#配置" class="header-anchor">#</a> 配置</h2> <div class="language-ruby extra-class"><pre class="language-ruby"><code>server<span class="token operator">:</span>
  <span class="token symbol">port</span><span class="token operator">:</span> <span class="token number">3006</span>
<span class="token symbol">spring</span><span class="token operator">:</span>
  <span class="token symbol">application</span><span class="token operator">:</span>
    <span class="token symbol">name</span><span class="token operator">:</span> <span class="token constant">SPEED</span><span class="token operator">-</span>bussiness<span class="token operator">-</span>order
  <span class="token symbol">cloud</span><span class="token operator">:</span>
    <span class="token symbol">nacos</span><span class="token operator">:</span>
      <span class="token comment">## 注册中心配置</span>
      <span class="token symbol">discovery</span><span class="token operator">:</span>
        <span class="token comment"># nacos的服务地址，nacos-server中IP地址:端口号</span>
        server<span class="token operator">-</span>addr<span class="token operator">:</span> <span class="token number">127.0</span><span class="token number">.0</span><span class="token number">.1</span><span class="token operator">:</span><span class="token number">8848</span>

  <span class="token symbol">redis</span><span class="token operator">:</span>
    <span class="token symbol">host</span><span class="token operator">:</span> <span class="token number">127.0</span><span class="token number">.0</span><span class="token number">.1</span>
    <span class="token symbol">password</span><span class="token operator">:</span>
    <span class="token symbol">port</span><span class="token operator">:</span> <span class="token number">6379</span>
    <span class="token symbol">timeout</span><span class="token operator">:</span> <span class="token number">15000</span>
    <span class="token symbol">jedis</span><span class="token operator">:</span>
      <span class="token symbol">pool</span><span class="token operator">:</span>
        max<span class="token operator">-</span>active<span class="token operator">:</span> <span class="token number">600</span>
        max<span class="token operator">-</span>idle<span class="token operator">:</span> <span class="token number">300</span>
        max<span class="token operator">-</span>wait<span class="token operator">:</span> <span class="token number">15000</span>
        min<span class="token operator">-</span>idle<span class="token operator">:</span> <span class="token number">10</span>

  <span class="token symbol">datasource</span><span class="token operator">:</span>
    <span class="token symbol">dynamic</span><span class="token operator">:</span>
      <span class="token comment"># 默认数据源</span>
      <span class="token symbol">primary</span><span class="token operator">:</span> master
      <span class="token symbol">datasource</span><span class="token operator">:</span>
        <span class="token symbol">master</span><span class="token operator">:</span>
          <span class="token symbol">driverClassName</span><span class="token operator">:</span> com<span class="token punctuation">.</span>mysql<span class="token punctuation">.</span>cj<span class="token punctuation">.</span>jdbc<span class="token punctuation">.</span>Driver
          <span class="token symbol">url</span><span class="token operator">:</span> jdbc<span class="token symbol">:mysql</span><span class="token operator">:</span><span class="token operator">/</span><span class="token operator">/</span><span class="token number">127.0</span><span class="token number">.0</span><span class="token number">.1</span><span class="token operator">:</span><span class="token number">3306</span><span class="token operator">/</span>auth<span class="token operator">-</span>server<span class="token operator">?</span>useUnicode<span class="token operator">=</span><span class="token boolean">true</span><span class="token operator">&amp;</span>characterEncoding<span class="token operator">=</span><span class="token constant">UTF</span><span class="token operator">-</span><span class="token number">8</span><span class="token operator">&amp;</span>zeroDateTimeBehavior<span class="token operator">=</span>convertToNull<span class="token operator">&amp;</span>useSSL<span class="token operator">=</span><span class="token boolean">false</span><span class="token operator">&amp;</span>allowMultiQueries<span class="token operator">=</span><span class="token boolean">true</span><span class="token operator">&amp;</span>serverTimezone<span class="token operator">=</span>Asia<span class="token operator">/</span>Shanghai
          <span class="token symbol">username</span><span class="token operator">:</span> root
          <span class="token symbol">password</span><span class="token operator">:</span> <span class="token number">1234</span>
        <span class="token symbol">slave</span><span class="token operator">:</span>
          <span class="token symbol">driverClassName</span><span class="token operator">:</span> com<span class="token punctuation">.</span>mysql<span class="token punctuation">.</span>cj<span class="token punctuation">.</span>jdbc<span class="token punctuation">.</span>Driver
          <span class="token symbol">url</span><span class="token operator">:</span> jdbc<span class="token symbol">:mysql</span><span class="token operator">:</span><span class="token operator">/</span><span class="token operator">/</span><span class="token number">127.0</span><span class="token number">.0</span><span class="token number">.1</span><span class="token operator">:</span><span class="token number">3306</span><span class="token operator">/</span>transit<span class="token operator">?</span>useUnicode<span class="token operator">=</span><span class="token boolean">true</span><span class="token operator">&amp;</span>characterEncoding<span class="token operator">=</span><span class="token constant">UTF</span><span class="token operator">-</span><span class="token number">8</span><span class="token operator">&amp;</span>zeroDateTimeBehavior<span class="token operator">=</span>convertToNull<span class="token operator">&amp;</span>useSSL<span class="token operator">=</span><span class="token boolean">false</span><span class="token operator">&amp;</span>allowMultiQueries<span class="token operator">=</span><span class="token boolean">true</span><span class="token operator">&amp;</span>serverTimezone<span class="token operator">=</span>Asia<span class="token operator">/</span>Shanghai
          <span class="token symbol">username</span><span class="token operator">:</span> root
          <span class="token symbol">password</span><span class="token operator">:</span> <span class="token number">1234</span>

<span class="token symbol">logging</span><span class="token operator">:</span>
  <span class="token symbol">level</span><span class="token operator">:</span>
    cn<span class="token punctuation">.</span>myjszl<span class="token punctuation">.</span>oauth2<span class="token punctuation">.</span>cloud<span class="token punctuation">.</span>order<span class="token punctuation">.</span>feign<span class="token operator">:</span> debug

</code></pre></div><h2 id="启动类"><a href="#启动类" class="header-anchor">#</a> 启动类</h2> <div class="language-ruby extra-class"><pre class="language-ruby"><code>package com<span class="token punctuation">.</span><span class="token constant">SPEED</span><span class="token punctuation">.</span>bussiness<span class="token punctuation">.</span>order<span class="token punctuation">;</span>

import org<span class="token punctuation">.</span>mybatis<span class="token punctuation">.</span>spring<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span>MapperScan<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>boot<span class="token punctuation">.</span>SpringApplication<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>boot<span class="token punctuation">.</span>autoconfigure<span class="token punctuation">.</span>SpringBootApplication<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>boot<span class="token punctuation">.</span>autoconfigure<span class="token punctuation">.</span>domain<span class="token punctuation">.</span>EntityScan<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>cloud<span class="token punctuation">.</span>client<span class="token punctuation">.</span>discovery<span class="token punctuation">.</span>EnableDiscoveryClient<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>context<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span>ComponentScan<span class="token punctuation">;</span>

<span class="token variable">@EnableDiscoveryClient</span>
<span class="token variable">@SpringBootApplication</span>
<span class="token variable">@ComponentScan</span><span class="token punctuation">(</span>basePackages <span class="token operator">=</span> <span class="token punctuation">{</span>
        <span class="token string-literal"><span class="token string">&quot;com.SPEED.common.security.filter&quot;</span></span><span class="token punctuation">,</span>
        <span class="token string-literal"><span class="token string">&quot;com.SPEED.common.config&quot;</span></span><span class="token punctuation">,</span>
        <span class="token string-literal"><span class="token string">&quot;com.SPEED.bussiness.order&quot;</span></span><span class="token punctuation">,</span>
        <span class="token string-literal"><span class="token string">&quot;com.SPEED.starter.*.*&quot;</span></span><span class="token punctuation">,</span>
        <span class="token string-literal"><span class="token string">&quot;com.SPEED.uid&quot;</span></span><span class="token punctuation">,</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token variable">@MapperScan</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token string-literal"><span class="token string">&quot;com.SPEED.starter.mapper&quot;</span></span><span class="token punctuation">,</span> <span class="token string-literal"><span class="token string">&quot;com.SPEED.bussiness.order.mapper&quot;</span></span><span class="token punctuation">,</span> <span class="token string-literal"><span class="token string">&quot;com.SPEED.uid.mapper&quot;</span></span><span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token variable">@EntityScan</span><span class="token punctuation">(</span>basePackages <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token string-literal"><span class="token string">&quot;com.SPEED.starter.model&quot;</span></span> <span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">SPEEDBussinessOrderApplication</span> <span class="token punctuation">{</span>

    <span class="token keyword">public</span> static void main<span class="token punctuation">(</span><span class="token builtin">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        SpringApplication<span class="token punctuation">.</span>run<span class="token punctuation">(</span>SPEEDBussinessOrderApplication<span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> args<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

<span class="token punctuation">}</span>

</code></pre></div><h1 id="认证鉴权中心"><a href="#认证鉴权中心" class="header-anchor">#</a> 认证鉴权中心</h1> <h2 id="oauth2-security"><a href="#oauth2-security" class="header-anchor">#</a> Oauth2 + Security</h2> <h3 id="用户名-密码登录"><a href="#用户名-密码登录" class="header-anchor">#</a> 用户名+密码登录</h3> <h3 id="手机号-密码"><a href="#手机号-密码" class="header-anchor">#</a> 手机号+密码</h3> <h1 id="权限设置"><a href="#权限设置" class="header-anchor">#</a> 权限设置</h1> <h2 id="接口权限"><a href="#接口权限" class="header-anchor">#</a> 接口权限</h2> <div class="language-ruby extra-class"><pre class="language-ruby"><code>        redisTemplate<span class="token punctuation">.</span>opsForHash<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>put<span class="token punctuation">(</span>SysConstant<span class="token punctuation">.</span><span class="token constant">OAUTH_URLS</span><span class="token punctuation">,</span><span class="token string-literal"><span class="token string">&quot;GET:/order/login/info&quot;</span></span><span class="token punctuation">,</span> Lists<span class="token punctuation">.</span>newArrayList<span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;ROLE_ADMIN&quot;</span></span><span class="token punctuation">,</span><span class="token string-literal"><span class="token string">&quot;ROLE_USER&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        redisTemplate<span class="token punctuation">.</span>opsForHash<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>put<span class="token punctuation">(</span>SysConstant<span class="token punctuation">.</span><span class="token constant">OAUTH_URLS</span><span class="token punctuation">,</span><span class="token string-literal"><span class="token string">&quot;GET:/order/login/admin&quot;</span></span><span class="token punctuation">,</span> Lists<span class="token punctuation">.</span>newArrayList<span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;ROLE_ADMIN&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        redisTemplate<span class="token punctuation">.</span>opsForHash<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>put<span class="token punctuation">(</span>SysConstant<span class="token punctuation">.</span><span class="token constant">OAUTH_URLS</span><span class="token punctuation">,</span><span class="token string-literal"><span class="token string">&quot;POST:/order/info&quot;</span></span><span class="token punctuation">,</span> Lists<span class="token punctuation">.</span>newArrayList<span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;ROLE_ADMIN&quot;</span></span><span class="token punctuation">,</span><span class="token string-literal"><span class="token string">&quot;ROLE_USER&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        redisTemplate<span class="token punctuation">.</span>opsForHash<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>put<span class="token punctuation">(</span>SysConstant<span class="token punctuation">.</span><span class="token constant">OAUTH_URLS</span><span class="token punctuation">,</span><span class="token string-literal"><span class="token string">&quot;GET:/order/listByUserId&quot;</span></span><span class="token punctuation">,</span> Lists<span class="token punctuation">.</span>newArrayList<span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;ROLE_ADMIN&quot;</span></span><span class="token punctuation">,</span><span class="token string-literal"><span class="token string">&quot;ROLE_USER&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        redisTemplate<span class="token punctuation">.</span>opsForHash<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>put<span class="token punctuation">(</span>SysConstant<span class="token punctuation">.</span><span class="token constant">OAUTH_URLS</span><span class="token punctuation">,</span><span class="token string-literal"><span class="token string">&quot;GET:/system/user/menu&quot;</span></span><span class="token punctuation">,</span> Lists<span class="token punctuation">.</span>newArrayList<span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;ROLE_ADMIN&quot;</span></span><span class="token punctuation">,</span><span class="token string-literal"><span class="token string">&quot;ROLE_USER&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        redisTemplate<span class="token punctuation">.</span>opsForHash<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>put<span class="token punctuation">(</span>SysConstant<span class="token punctuation">.</span><span class="token constant">OAUTH_URLS</span><span class="token punctuation">,</span><span class="token string-literal"><span class="token string">&quot;GET:/system/user/info&quot;</span></span><span class="token punctuation">,</span> Lists<span class="token punctuation">.</span>newArrayList<span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;ROLE_ADMIN&quot;</span></span><span class="token punctuation">,</span><span class="token string-literal"><span class="token string">&quot;ROLE_USER&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        redisTemplate<span class="token punctuation">.</span>opsForHash<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>put<span class="token punctuation">(</span>SysConstant<span class="token punctuation">.</span><span class="token constant">OAUTH_URLS</span><span class="token punctuation">,</span><span class="token string-literal"><span class="token string">&quot;GET:/system/getUID&quot;</span></span><span class="token punctuation">,</span> Lists<span class="token punctuation">.</span>newArrayList<span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;ROLE_ADMIN&quot;</span></span><span class="token punctuation">,</span><span class="token string-literal"><span class="token string">&quot;ROLE_USER&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        redisTemplate<span class="token punctuation">.</span>opsForHash<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>put<span class="token punctuation">(</span>SysConstant<span class="token punctuation">.</span><span class="token constant">OAUTH_URLS</span><span class="token punctuation">,</span><span class="token string-literal"><span class="token string">&quot;GET:/bussiness-order/selectList&quot;</span></span><span class="token punctuation">,</span> Lists<span class="token punctuation">.</span>newArrayList<span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;ROLE_ADMIN&quot;</span></span><span class="token punctuation">,</span><span class="token string-literal"><span class="token string">&quot;ROLE_USER&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        redisTemplate<span class="token punctuation">.</span>opsForHash<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>put<span class="token punctuation">(</span>SysConstant<span class="token punctuation">.</span><span class="token constant">OAUTH_URLS</span><span class="token punctuation">,</span><span class="token string-literal"><span class="token string">&quot;POST:/bussiness-order/insert&quot;</span></span><span class="token punctuation">,</span> Lists<span class="token punctuation">.</span>newArrayList<span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;ROLE_ADMIN&quot;</span></span><span class="token punctuation">,</span><span class="token string-literal"><span class="token string">&quot;ROLE_USER&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        redisTemplate<span class="token punctuation">.</span>opsForHash<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>put<span class="token punctuation">(</span>SysConstant<span class="token punctuation">.</span><span class="token constant">OAUTH_URLS</span><span class="token punctuation">,</span><span class="token string-literal"><span class="token string">&quot;POST:/bussiness-order/update&quot;</span></span><span class="token punctuation">,</span> Lists<span class="token punctuation">.</span>newArrayList<span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;ROLE_ADMIN&quot;</span></span><span class="token punctuation">,</span><span class="token string-literal"><span class="token string">&quot;ROLE_USER&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        redisTemplate<span class="token punctuation">.</span>opsForHash<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>put<span class="token punctuation">(</span>SysConstant<span class="token punctuation">.</span><span class="token constant">OAUTH_URLS</span><span class="token punctuation">,</span><span class="token string-literal"><span class="token string">&quot;DELETE:/bussiness-order/delete/**&quot;</span></span><span class="token punctuation">,</span> Lists<span class="token punctuation">.</span>newArrayList<span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;ROLE_ADMIN&quot;</span></span><span class="token punctuation">,</span><span class="token string-literal"><span class="token string">&quot;ROLE_USER&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        redisTemplate<span class="token punctuation">.</span>opsForHash<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>put<span class="token punctuation">(</span>SysConstant<span class="token punctuation">.</span><span class="token constant">OAUTH_URLS</span><span class="token punctuation">,</span><span class="token string-literal"><span class="token string">&quot;GET:/bussiness-order/hello&quot;</span></span><span class="token punctuation">,</span> Lists<span class="token punctuation">.</span>newArrayList<span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;ROLE_ADMIN&quot;</span></span><span class="token punctuation">,</span><span class="token string-literal"><span class="token string">&quot;ROLE_USER&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        redisTemplate<span class="token punctuation">.</span>opsForHash<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>put<span class="token punctuation">(</span>SysConstant<span class="token punctuation">.</span><span class="token constant">OAUTH_URLS</span><span class="token punctuation">,</span><span class="token string-literal"><span class="token string">&quot;GET:/oauth/logout&quot;</span></span><span class="token punctuation">,</span> Lists<span class="token punctuation">.</span>newArrayList<span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;ROLE_ADMIN&quot;</span></span><span class="token punctuation">,</span><span class="token string-literal"><span class="token string">&quot;ROLE_USER&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><h1 id="网关服务"><a href="#网关服务" class="header-anchor">#</a> 网关服务</h1> <h2 id="跨域设置"><a href="#跨域设置" class="header-anchor">#</a> 跨域设置</h2> <h3 id="手动配置方式实现"><a href="#手动配置方式实现" class="header-anchor">#</a> 手动配置方式实现</h3> <div class="language-ruby extra-class"><pre class="language-ruby"><code>package com<span class="token punctuation">.</span><span class="token constant">SPEED</span><span class="token punctuation">.</span>gateway<span class="token punctuation">.</span>filter<span class="token punctuation">;</span>

import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>http<span class="token punctuation">.</span>HttpHeaders<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>http<span class="token punctuation">.</span>HttpMethod<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>http<span class="token punctuation">.</span>HttpStatus<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>http<span class="token punctuation">.</span>server<span class="token punctuation">.</span>reactive<span class="token punctuation">.</span>ServerHttpRequest<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>http<span class="token punctuation">.</span>server<span class="token punctuation">.</span>reactive<span class="token punctuation">.</span>ServerHttpResponse<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>stereotype<span class="token punctuation">.</span>Component<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>web<span class="token punctuation">.</span>cors<span class="token punctuation">.</span>reactive<span class="token punctuation">.</span>CorsUtils<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>web<span class="token punctuation">.</span>server<span class="token punctuation">.</span>ServerWebExchange<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>web<span class="token punctuation">.</span>server<span class="token punctuation">.</span>WebFilter<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>web<span class="token punctuation">.</span>server<span class="token punctuation">.</span>WebFilterChain<span class="token punctuation">;</span>
import reactor<span class="token punctuation">.</span>core<span class="token punctuation">.</span>publisher<span class="token punctuation">.</span>Mono<span class="token punctuation">;</span>

<span class="token operator">/</span><span class="token operator">**</span>
 <span class="token operator">*</span> 跨域的配置
 <span class="token operator">*</span><span class="token operator">/</span>
<span class="token variable">@Component</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">CorsFilter</span> implements WebFilter <span class="token punctuation">{</span>
    
    <span class="token variable">@Override</span>
    <span class="token keyword">public</span> Mono<span class="token operator">&lt;</span>Void<span class="token operator">&gt;</span> filter<span class="token punctuation">(</span>ServerWebExchange exchange<span class="token punctuation">,</span> WebFilterChain chain<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        ServerHttpRequest request <span class="token operator">=</span> exchange<span class="token punctuation">.</span>getRequest<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>CorsUtils<span class="token punctuation">.</span>isCorsRequest<span class="token punctuation">(</span>request<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            HttpHeaders requestHeaders <span class="token operator">=</span> request<span class="token punctuation">.</span>getHeaders<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            ServerHttpResponse response <span class="token operator">=</span> exchange<span class="token punctuation">.</span>getResponse<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            HttpMethod requestMethod <span class="token operator">=</span> requestHeaders<span class="token punctuation">.</span>getAccessControlRequestMethod<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            HttpHeaders headers <span class="token operator">=</span> response<span class="token punctuation">.</span>getHeaders<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            headers<span class="token punctuation">.</span>add<span class="token punctuation">(</span>HttpHeaders<span class="token punctuation">.</span><span class="token constant">ACCESS_CONTROL_ALLOW_ORIGIN</span><span class="token punctuation">,</span> requestHeaders<span class="token punctuation">.</span>getOrigin<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            headers<span class="token punctuation">.</span>addAll<span class="token punctuation">(</span>HttpHeaders<span class="token punctuation">.</span><span class="token constant">ACCESS_CONTROL_ALLOW_HEADERS</span><span class="token punctuation">,</span> requestHeaders<span class="token punctuation">.</span>getAccessControlRequestHeaders<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span>requestMethod <span class="token operator">!=</span> null<span class="token punctuation">)</span> <span class="token punctuation">{</span>
                headers<span class="token punctuation">.</span>add<span class="token punctuation">(</span>HttpHeaders<span class="token punctuation">.</span><span class="token constant">ACCESS_CONTROL_ALLOW_METHODS</span><span class="token punctuation">,</span> requestMethod<span class="token punctuation">.</span>name<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            headers<span class="token punctuation">.</span>add<span class="token punctuation">(</span>HttpHeaders<span class="token punctuation">.</span><span class="token constant">ACCESS_CONTROL_ALLOW_CREDENTIALS</span><span class="token punctuation">,</span> <span class="token string-literal"><span class="token string">&quot;true&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            headers<span class="token punctuation">.</span>add<span class="token punctuation">(</span>HttpHeaders<span class="token punctuation">.</span><span class="token constant">ACCESS_CONTROL_EXPOSE_HEADERS</span><span class="token punctuation">,</span> <span class="token string-literal"><span class="token string">&quot;*&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            headers<span class="token punctuation">.</span>add<span class="token punctuation">(</span>HttpHeaders<span class="token punctuation">.</span><span class="token constant">ACCESS_CONTROL_MAX_AGE</span><span class="token punctuation">,</span> <span class="token string-literal"><span class="token string">&quot;18000L&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span>request<span class="token punctuation">.</span>getMethod<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">==</span> HttpMethod<span class="token punctuation">.</span><span class="token constant">OPTIONS</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                response<span class="token punctuation">.</span>setStatusCode<span class="token punctuation">(</span>HttpStatus<span class="token punctuation">.</span><span class="token constant">OK</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token keyword">return</span> Mono<span class="token punctuation">.</span>empty<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">return</span> chain<span class="token punctuation">.</span>filter<span class="token punctuation">(</span>exchange<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

</code></pre></div><h3 id="文件配置方式实现"><a href="#文件配置方式实现" class="header-anchor">#</a> 文件配置方式实现</h3> <div class="language-ruby extra-class"><pre class="language-ruby"><code>spring<span class="token operator">:</span>
    <span class="token symbol">cloud</span><span class="token operator">:</span>
        <span class="token symbol">gateway</span><span class="token operator">:</span>
          <span class="token symbol">globalcors</span><span class="token operator">:</span>
            cors<span class="token operator">-</span>configurations<span class="token operator">:</span>
              <span class="token string-literal"><span class="token string">'[/**]'</span></span><span class="token operator">:</span>
                <span class="token symbol">allowedOrigins</span><span class="token operator">:</span> <span class="token string-literal"><span class="token string">&quot;*&quot;</span></span>
                <span class="token symbol">allowedHeaders</span><span class="token operator">:</span> <span class="token string-literal"><span class="token string">&quot;*&quot;</span></span>
                <span class="token symbol">allowedMethods</span><span class="token operator">:</span> <span class="token string-literal"><span class="token string">&quot;*&quot;</span></span>
          default<span class="token operator">-</span>filters<span class="token operator">:</span>
          <span class="token operator">-</span> DedupeResponseHeader<span class="token operator">=</span>Vary Access<span class="token operator">-</span>Control<span class="token operator">-</span>Allow<span class="token operator">-</span>Origin Access<span class="token operator">-</span>Control<span class="token operator">-</span>Allow<span class="token operator">-</span>Credentials<span class="token punctuation">,</span> <span class="token constant">RETAIN_FIRST</span>
</code></pre></div><h2 id="服务限流熔断"><a href="#服务限流熔断" class="header-anchor">#</a> 服务限流熔断</h2> <h3 id="配置方式实现"><a href="#配置方式实现" class="header-anchor">#</a> 配置方式实现</h3> <div class="language-ruby extra-class"><pre class="language-ruby"><code>    <span class="token comment">## 整合sentinel，配置sentinel控制台的地址</span>
    <span class="token symbol">sentinel</span><span class="token operator">:</span>
      <span class="token symbol">transport</span><span class="token operator">:</span>
        <span class="token comment">## 指定控制台的地址，默认端口 8080</span>
        <span class="token symbol">dashboard</span><span class="token operator">:</span> localhost<span class="token operator">:</span><span class="token number">8080</span>
      <span class="token comment">#配置限流之后，响应内容</span>
      <span class="token symbol">scg</span><span class="token operator">:</span>
        <span class="token symbol">fallback</span><span class="token operator">:</span>
          <span class="token comment">## 两种模式，一种是response返回文字提示信息，</span>
          <span class="token comment">## 一种是redirect，重定向跳转，需要同时配置redirect(跳转的uri)</span>
          <span class="token symbol">mode</span><span class="token operator">:</span> response
          <span class="token comment">## 响应的状态</span>
          response<span class="token operator">-</span>status<span class="token operator">:</span> <span class="token number">200</span>
          <span class="token comment">## 响应体</span>
          response<span class="token operator">-</span>body<span class="token operator">:</span> <span class="token string-literal"><span class="token string">'{&quot;code&quot;: 200,&quot;message&quot;: &quot;请求失败，稍后重试！&quot;}'</span></span>
          <span class="token comment">## 两种模式，一种是response返回文字提示信息，一种是redirect，重定向跳转，需要同时配置redirect(跳转的uri)</span>
          <span class="token comment">## mode: redirect</span>
          <span class="token comment">## 跳转的URL</span>
          <span class="token comment">## redirect: http://www.baidu.com</span>
</code></pre></div><h3 id="自定义方式实现"><a href="#自定义方式实现" class="header-anchor">#</a> 自定义方式实现</h3> <div class="language-ruby extra-class"><pre class="language-ruby"><code>package com<span class="token punctuation">.</span><span class="token constant">SPEED</span><span class="token punctuation">.</span>gateway<span class="token punctuation">.</span>config<span class="token punctuation">.</span>sentinel<span class="token punctuation">;</span>

import com<span class="token punctuation">.</span>alibaba<span class="token punctuation">.</span>csp<span class="token punctuation">.</span>sentinel<span class="token punctuation">.</span>adapter<span class="token punctuation">.</span>gateway<span class="token punctuation">.</span>sc<span class="token punctuation">.</span>callback<span class="token punctuation">.</span>BlockRequestHandler<span class="token punctuation">;</span>
import com<span class="token punctuation">.</span>alibaba<span class="token punctuation">.</span>csp<span class="token punctuation">.</span>sentinel<span class="token punctuation">.</span>adapter<span class="token punctuation">.</span>gateway<span class="token punctuation">.</span>sc<span class="token punctuation">.</span>callback<span class="token punctuation">.</span>GatewayCallbackManager<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>http<span class="token punctuation">.</span>HttpStatus<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>http<span class="token punctuation">.</span>MediaType<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>web<span class="token punctuation">.</span>reactive<span class="token punctuation">.</span>function<span class="token punctuation">.</span>BodyInserters<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>web<span class="token punctuation">.</span>reactive<span class="token punctuation">.</span>function<span class="token punctuation">.</span>server<span class="token punctuation">.</span>ServerResponse<span class="token punctuation">;</span>

import javax<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span>PostConstruct<span class="token punctuation">;</span>
import java<span class="token punctuation">.</span>util<span class="token punctuation">.</span>HashMap<span class="token punctuation">;</span>
import java<span class="token punctuation">.</span>util<span class="token punctuation">.</span>Map<span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">GatewayConfig</span> <span class="token punctuation">{</span>
    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 自定义限流处理器
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token variable">@PostConstruct</span>
    <span class="token keyword">public</span> void initBlockHandlers<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        BlockRequestHandler blockHandler <span class="token operator">=</span> <span class="token punctuation">(</span>serverWebExchange<span class="token punctuation">,</span> throwable<span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">&gt;</span> <span class="token punctuation">{</span>
            Map map <span class="token operator">=</span> <span class="token keyword">new</span> HashMap<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            map<span class="token punctuation">.</span>put<span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;code&quot;</span></span><span class="token punctuation">,</span> <span class="token number">200</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            map<span class="token punctuation">.</span>put<span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;message&quot;</span></span><span class="token punctuation">,</span> <span class="token string-literal"><span class="token string">&quot;请求失败，稍后重试！&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">return</span> ServerResponse<span class="token punctuation">.</span>status<span class="token punctuation">(</span>HttpStatus<span class="token punctuation">.</span><span class="token constant">OK</span><span class="token punctuation">)</span>
                    <span class="token punctuation">.</span>contentType<span class="token punctuation">(</span>MediaType<span class="token punctuation">.</span><span class="token constant">APPLICATION_JSON_UTF8</span><span class="token punctuation">)</span>
                    <span class="token punctuation">.</span>body<span class="token punctuation">(</span>BodyInserters<span class="token punctuation">.</span>fromObject<span class="token punctuation">(</span>map<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">;</span>
        GatewayCallbackManager<span class="token punctuation">.</span>setBlockHandler<span class="token punctuation">(</span>blockHandler<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre></div><h2 id="网关负载均衡路由"><a href="#网关负载均衡路由" class="header-anchor">#</a> 网关负载均衡路由</h2> <div class="language-ruby extra-class"><pre class="language-ruby"><code>      <span class="token comment">## 路由</span>
      <span class="token symbol">routes</span><span class="token operator">:</span>
        <span class="token comment">## id只要唯一即可，名称任意</span>
        <span class="token operator">-</span> id<span class="token operator">:</span> <span class="token constant">SPEED</span><span class="token operator">-</span>oauth2<span class="token operator">-</span>server
          <span class="token symbol">uri</span><span class="token operator">:</span> lb<span class="token operator">:</span><span class="token operator">/</span><span class="token operator">/</span><span class="token constant">SPEED</span><span class="token operator">-</span>oauth2<span class="token operator">-</span>server
          <span class="token symbol">predicates</span><span class="token operator">:</span>
            <span class="token comment">## Path Route Predicate Factory断言</span>
            <span class="token operator">-</span> Path<span class="token operator">=</span><span class="token operator">/</span>oauth<span class="token operator">/</span><span class="token operator">**</span>
        <span class="token operator">-</span> id<span class="token operator">:</span> <span class="token constant">SPEED</span><span class="token operator">-</span>order
          <span class="token symbol">uri</span><span class="token operator">:</span> lb<span class="token operator">:</span><span class="token operator">/</span><span class="token operator">/</span><span class="token constant">SPEED</span><span class="token operator">-</span>order
          <span class="token symbol">predicates</span><span class="token operator">:</span>
            <span class="token comment">## Path Route Predicate Factory断言</span>
            <span class="token operator">-</span> Path<span class="token operator">=</span><span class="token operator">/</span>order<span class="token operator">/</span><span class="token operator">**</span>
        <span class="token operator">-</span> id<span class="token operator">:</span> <span class="token constant">SPEED</span><span class="token operator">-</span>system
          <span class="token symbol">uri</span><span class="token operator">:</span> lb<span class="token operator">:</span><span class="token operator">/</span><span class="token operator">/</span><span class="token constant">SPEED</span><span class="token operator">-</span>system
          <span class="token symbol">predicates</span><span class="token operator">:</span>
            <span class="token comment">## Path Route Predicate Factory断言</span>
            <span class="token operator">-</span> Path<span class="token operator">=</span><span class="token operator">/</span>system<span class="token operator">/</span><span class="token operator">**</span>
        <span class="token operator">-</span> id<span class="token operator">:</span> <span class="token constant">SPEED</span><span class="token operator">-</span>bussiness<span class="token operator">-</span>order
          <span class="token symbol">uri</span><span class="token operator">:</span> lb<span class="token operator">:</span><span class="token operator">/</span><span class="token operator">/</span><span class="token constant">SPEED</span><span class="token operator">-</span>bussiness<span class="token operator">-</span>order
          <span class="token symbol">predicates</span><span class="token operator">:</span>
            <span class="token comment">## Path Route Predicate Factory断言</span>
            <span class="token operator">-</span> Path<span class="token operator">=</span><span class="token operator">/</span>bussiness<span class="token operator">-</span>order<span class="token operator">/</span><span class="token operator">**</span>
</code></pre></div><h1 id="链路追踪"><a href="#链路追踪" class="header-anchor">#</a> 链路追踪</h1> <h2 id="依赖-3"><a href="#依赖-3" class="header-anchor">#</a> 依赖</h2> <div class="language-ruby extra-class"><pre class="language-ruby"><code>        <span class="token operator">&lt;</span><span class="token operator">!</span><span class="token operator">-</span><span class="token operator">-</span>logback<span class="token operator">-</span>skywalking的依賴<span class="token operator">-</span><span class="token operator">-</span><span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span>dependency<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>groupId<span class="token operator">&gt;</span>org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>skywalking<span class="token operator">&lt;</span><span class="token operator">/</span>groupId<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>artifactId<span class="token operator">&gt;</span>apm<span class="token operator">-</span>toolkit<span class="token operator">-</span>logback<span class="token operator">-</span><span class="token number">1.</span>x<span class="token operator">&lt;</span><span class="token operator">/</span>artifactId<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>version<span class="token operator">&gt;</span><span class="token number">8.7</span><span class="token number">.0</span><span class="token operator">&lt;</span><span class="token operator">/</span>version<span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span><span class="token operator">/</span>dependency<span class="token operator">&gt;</span>
</code></pre></div><h2 id="启动本地服务"><a href="#启动本地服务" class="header-anchor">#</a> 启动本地服务</h2> <h2 id="回调报警"><a href="#回调报警" class="header-anchor">#</a> 回调报警</h2> <div class="language-ruby extra-class"><pre class="language-ruby"><code>package com<span class="token punctuation">.</span><span class="token constant">SPEED</span><span class="token punctuation">.</span>skywalking<span class="token punctuation">.</span>controller<span class="token punctuation">;</span>

import com<span class="token punctuation">.</span>alibaba<span class="token punctuation">.</span>fastjson<span class="token punctuation">.</span><span class="token constant">JSON</span><span class="token punctuation">;</span>
import com<span class="token punctuation">.</span><span class="token constant">SPEED</span><span class="token punctuation">.</span>skywalking<span class="token punctuation">.</span>model<span class="token punctuation">.</span>AlarmMessage<span class="token punctuation">;</span>
import lombok<span class="token punctuation">.</span>extern<span class="token punctuation">.</span>slf4j<span class="token punctuation">.</span>Slf4j<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>web<span class="token punctuation">.</span>bind<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span>PostMapping<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>web<span class="token punctuation">.</span>bind<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span>RequestBody<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>web<span class="token punctuation">.</span>bind<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span>RequestMapping<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>web<span class="token punctuation">.</span>bind<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span>RestController<span class="token punctuation">;</span>
import java<span class="token punctuation">.</span>util<span class="token punctuation">.</span>List<span class="token punctuation">;</span>

<span class="token variable">@RestController</span>
<span class="token variable">@RequestMapping</span><span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;/alarm&quot;</span></span><span class="token punctuation">)</span>
<span class="token variable">@Slf4j</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">AlarmController</span> <span class="token punctuation">{</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> skywalking回调方法，一旦触发告警，则会调用这个接口
     <span class="token operator">*</span> <span class="token variable">@param</span> list 指定的参数，必须按照规则定义
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token variable">@PostMapping</span><span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;/receive&quot;</span></span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> void receive<span class="token punctuation">(</span><span class="token variable">@RequestBody</span> List<span class="token operator">&lt;</span>AlarmMessage<span class="token operator">&gt;</span> list<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token operator">/</span><span class="token operator">/</span>todo 仅仅打印<span class="token constant">JSON</span>，至于发送邮件、微信、钉钉自己根据业务需求完成
        log<span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;------------------------&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        log<span class="token punctuation">.</span>info<span class="token punctuation">(</span><span class="token constant">JSON</span><span class="token punctuation">.</span>toJSONString<span class="token punctuation">(</span>list<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

</code></pre></div></div> <footer class="page-edit"><!----> <!----></footer> <!----> </main></div><div class="global-ui"></div></div>
    <script src="/assets/js/app.9e59f384.js" defer></script><script src="/assets/js/2.61252cf6.js" defer></script><script src="/assets/js/14.5f5c406e.js" defer></script>
  </body>
</html>
